<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
          <el-menu-item index="1">修改密码</el-menu-item>
        </el-menu>
      </el-header>
      <el-main>
        <el-form ref="loginForm" :model="userInfo" style="max-width: 600px" :rules="userInfoRules" >

          <el-form-item label="用户名" prop="userName" label-width="100">
            <el-input v-model="userInfo.userName" placeholder="请输入用户名" />
          </el-form-item>
          <el-form-item label="密码" prop="pwd" label-width="100">
            <el-input v-model="userInfo.pwd" placeholder="请输入密码"/>
          </el-form-item>
          <el-form-item label="用户类型" label-position="right" prop="userType" label-width="100">
          <el-radio-group v-model="userInfo.userType">
            <el-radio-button value="1">学生</el-radio-button>
            <el-radio-button value="2">教师</el-radio-button>
            <el-radio-button value="3">管理员</el-radio-button>
          </el-radio-group>
        </el-form-item>
        </el-form>
      
          <el-button type="primary" @click="handleLogin" style="margin-left: 100px;" v-no-more-click>登录</el-button>
          
      </el-main>
    </el-container>
  </div>
</template>
<script setup>
import { getCurrentInstance, ref } from "vue"
import request from '@/utils/request'
const userInfoRules={
  userName:[
    {required:true,message:"请输入用户名",trigger:'blur'}
  ],
  password:[
    {required:true,message:"请输入密码",trigger:'blur'}
  ],
  userType:[
    {required:true,message:"选择用户类型",trigger:'blur'}
  ]
}
const { proxy } = getCurrentInstance();
const userInfo = ref({})


function handleLogin(){
  proxy.$refs["loginForm"].validate(valid=>{
    if(valid){      
      console.log(userInfo.value);
      
      request({
        url:'/user-manager/login',
        method:'POST',
        data:userInfo.value
      }).then(res=>{        
        console.log(res);
        if(res.data.code==200){
          proxy.$message.success(res.data.message)
        }else{
          proxy.$message.error(res.data.message)
        }
        
      })
    }
  })

}
</script>
<style  scoped>
.common-layout {
  display: flex;
  justify-content: right;
  align-items: center;
  height: 100%;
  width: 500px;
  background-size: cover;
  /* background-image: url(../assets/images/bg1.jpg); */
  background-repeat: no-repeat;
  margin-top: 0px;
  margin-left: 600px;
}


</style>